package com.huike.clues.service.impl;


import com.huike.clues.domain.TbClue;
import com.huike.clues.domain.TbClueTrackRecord;
import com.huike.clues.domain.vo.ClueTrackRecordVo;
import com.huike.clues.mapper.TbClueMapper;
import com.huike.clues.mapper.TbClueTrackRecordMapper;
import com.huike.clues.service.ITbClueTrackRecordService;
import com.huike.common.core.domain.AjaxResult;
import com.huike.common.core.page.TableDataInfo;
import com.huike.common.utils.DateUtils;
import com.huike.common.utils.SecurityUtils;
import com.huike.common.utils.bean.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * 线索跟进记录Service业务层处理
 */
@Service
public class TbClueTrackRecordServiceImpl implements ITbClueTrackRecordService {

    @Autowired
    private TbClueMapper clueMapper;
    @Autowired
    private TbClueTrackRecordMapper recordMapper;

    /**
     * 新增线索跟进记录
     */
    @Override
    public void add(ClueTrackRecordVo tbClueTrackRecord) {
        TbClue tbClue = new TbClue();
        BeanUtils.copyProperties(tbClueTrackRecord,tbClue);
        tbClue.setStatus(TbClue.StatusType.FOLLOWING.getValue());
        tbClue.setId(tbClueTrackRecord.getClueId());
        clueMapper.updateTbClue(tbClue);

        String username = SecurityUtils.getUsername();
        TbClueTrackRecord clueTrackRecord = new TbClueTrackRecord();
        clueTrackRecord.setCreateBy(username);
        clueTrackRecord.setCreateTime(new Date());
        BeanUtils.copyProperties(tbClueTrackRecord,clueTrackRecord);
        recordMapper.add(clueTrackRecord);
    }

    /**
     * 查询线索跟进记录列表
     */
    @Override
    public List<TbClueTrackRecord> list(Long clueId) {
        List<TbClueTrackRecord> list = recordMapper.list(clueId);
        return list;
    }
}
